var t = require("../../utils/api.js");

getApp();

Page({
    data: {
        bought: [],
        page: 2,
        goodsInfo: {},
        showLoding: !1
    },
    onLoad: function(a) {
        var o = a.id, e = a.at_id, n = this;
        wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        }), t.getGoods({
            gid: o,
            at_id: e
        }).then(function(t) {
            n.setData({
                goodsInfo: t.data[0]
            }), console.log(t.data[0]), t.data[0].action.at_end_time && n.countDown();
        }), t.getAllBuyPeople({
            gid: o
        }).then(function(a) {
            console.log(a);
            var e = [];
            if (0 == a.errno) {
                for (var i in a.data) a.data[i].m_photo = a.data[i].m_photo.replace(/[\r\n]/g, "");
                e = a.data, a.data.length < 10 ? t.getAllBuyPeople({
                    gid: o,
                    page: 2
                }).then(function(t) {
                    if (console.log(t), 0 == t.errno) {
                        for (var a in t.data) t.data[a].m_photo = t.data[a].m_photo.replace(/[\r\n]/g, "");
                        console.log(t), e = 0 == t.data.length ? e : e.concat(t.data), n.setData({
                            page: 3
                        });
                    }
                    n.setData({
                        bought: e,
                        id: o
                    });
                }) : n.setData({
                    bought: e,
                    id: o
                }), console.log(n.data.bought);
            } else n.setData({
                bought: ""
            });
            n.setData({
                showLoding: !0
            });
        });
    },
    onReachBottom: function(a) {
        var o = this;
        t.getAllBuyPeople({
            gid: o.data.id,
            page: o.data.page
        }).then(function(t) {
            if (console.log(t), 0 == t.errno) {
                for (var a in t.data) t.data[a].m_photo = t.data[a].m_photo.replace(/[\r\n]/g, "");
                var e = parseInt(o.data.page) + parseInt(1), n = o.data.bought.concat(t.data);
                console.log(o.data.data), o.setData({
                    bought: n,
                    page: e
                });
            } else wx.showToast({
                title: "没有更多数据了",
                icon: "none",
                duration: 2e3
            });
        });
    },
    onShareAppMessage: function(t) {
        var a = this;
        "button" === t.from && console.log(t.target);
        var o = getCurrentPages(), e = (o[o.length - 1], o[o.length - 2].data);
        return console.log("/pages/goods/goodsDetail?id=" + e.code.id + "&&at_id=" + e.code.a_id + "&&actEndTime=" + e.code.actEndTime + "&&p_id=" + e.member.m_id), 
        console.log(e.banners[0]), {
            title: a.data.goodsInfo.gc_name,
            path: "/pages/goods/goodsDetail?id=" + e.code.id + "&&at_id=" + e.code.a_id + "&&actEndTime=" + e.code.actEndTime + "&&p_id=" + e.member.m_id,
            imageUrl: e.banners[0]
        };
    },
    timeFormat: function(t) {
        return t < 10 ? "0" + t : t;
    },
    countDown: function() {
        var t = new Date().getTime(), a = [], o = 1e3 * parseInt(this.data.goodsInfo.action.at_end_time), e = null;
        if (o - t > 0) {
            var n = (o - t) / 1e3, i = parseInt(n / 86400), d = parseInt(n % 86400 / 3600), s = parseInt(n % 86400 % 3600 / 60), g = parseInt(n % 86400 % 3600 % 60);
            e = {
                day: i,
                hou: this.timeFormat(d),
                min: this.timeFormat(s),
                sec: this.timeFormat(g)
            };
        } else e = {
            day: "0",
            hou: "00",
            min: "00",
            sec: "00"
        };
        a.push(e), this.setData({
            countDownList: a
        }), setTimeout(this.countDown, 1e3);
    }
});